﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QD.Web.Upload
{
    public class UploadPath
    {
        public UploadPath()
        { }

        private static string Combine(string path1, string path2, char character, char replace)
        {
            if (string.IsNullOrEmpty(path1))
            {
                return path2;
            }
            if (string.IsNullOrEmpty(path2))
            {
                return path1;
            }
            path1 = path1.Replace(character, replace);
            path2 = path2.Replace(character, replace);
            if ((path1[path1.Length - 1] == replace) && (path2[0] == replace))
            {
                return (path1 + path2.Substring(1));
            }
            if ((path1[path1.Length - 1] != replace) && (path2[0] != replace))
            {
                return (path1 + replace + path2);
            }
            return (path1 + path2);
        }
        public static string CombinePath(string path1, string path2)
        {
            return Combine(path1, path2, '/', '\\');
        }
        public static string CombinePath(string path1, string path2, string path3)
        {
            return CombinePath(CombinePath(path1, path2), path3);
        }
        public static string CombineWebPath(string path1, string path2)
        {
            return Combine(path1, path2, '\\', '/');
        }
        public static string CombineWebPath(string path1, string path2, string path3)
        {
            return CombineWebPath(CombineWebPath(path1, path2), path3);
        }
    }
}
